#include "clickableframe.h"

#include <QtGui>

ClickableFrame::ClickableFrame(QString filename, QWidget *parent) : QGroupBox(parent), m_filename(filename)
{
    setTitle(m_filename.section('/', -1));
    this->setAlignment(Qt::AlignHCenter);
    //QLabel *label = new QLabel(this);

    QPixmap pixmap(m_filename);
    QPushButton *button = new QPushButton(this);
    button->setIcon(pixmap);
    button->setIconSize(pixmap.size());
    button->setFixedSize(pixmap.size());
    button->setFlat(true);
    //button->setCheckable(true);

    //label->setPixmap(QPixmap(filename));
    QGridLayout *layout = new QGridLayout(this);
    layout->addWidget(button, 0, 0);

    setLayout(layout);

    connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
}

void ClickableFrame::buttonClicked()
{
    emit clicked(m_filename);
}

void ClickableFrame::setActive(bool active)
{
    if (active)
        setBackgroundRole(QPalette::Shadow);
    else
        setBackgroundRole(QPalette::NoRole);

    setAutoFillBackground(active);
}
